package cn.hill4j.tool.spring.std.ds.common;

import cn.hill4j.tool.spring.std.ds.customer.service.ICustomerService;
import cn.hill4j.tool.spring.std.ds.user.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * TODO Description
 *
 * @author: hillchen
 * Date: 2022-08-08 16:09
 */
@Service
public class TxService implements ITxService{
    @Resource
    ICustomerService customerService;
    @Resource
    IUserService userService;
    @Override
    @Transactional
    public void saveUserAndCustomer(String name) {
        customerService.saveByName(name);
        userService.saveByName(name);
    }

    @Override
    public void save2User(String name) {
        userService.saveByName(name);
        if (Objects.equals("hill3",name)){
            throw new RuntimeException("");
        }
        userService.saveByName(name + "11");
        throw new RuntimeException("");
    }

    @Override
    @Transactional
    public void save2CustomerAndFindUser(String name) {
        customerService.saveByName(name);
        userService.findByName(name);
        customerService.saveByName(name + "11");
    }
}
